********************************************************************************
* MASTER DO FILE
* Replicates all Tables and Figures in the Publication and Appendix
********************************************************************************

clear
clear matrix
set more off
set scheme s1color
estimates clear
graph drop _all
set matsize 2500
log close _all

********************************************************************************
* DIRECTIONS:
* Step 1: Set the working directory

cd "../Do"

* Step 2: Set the Haver directory

// set haverdir "Haver", perm

* Step 3: Set the below local to 1 to replicate figures

local replicate_figures = 1

* Step 4: Set the below local to 1 to replicate tables as LaTeX fragments. 

local replicate_tables = 1

* Step 5: Set the below local to 1 to compile master .tex files into .pdf files. 
* [NOTE: If this step doesn't work with your LaTeX software, compile the master 
* .tex files directly in the "Tables" folder. See the README for details.]

local compile = 1

* Step 5: RUN this file in STATA.
********************************************************************************

do durables_merge_replicate
do nondurables_merge_replicate
do sample_overlap

if `replicate_figures' == 1 {
	do create_figure1a
	do create_figure1b
	do create_figure2
	do create_figureA1
	do create_figureA2
	do create_figureA3_A4
	do create_figureA5
	do create_figureA6
}

if `replicate_tables' == 1 {
	do create_table1a_sumstats
	do create_table1b_sumstats_mort
	do create_table2_durables_real2var_tabs
	do create_table3_margins_tables_durables
	do create_table4_reg_tabs_nondurables
	do create_table5_margins_tables_nondurables
	do create_tableA3_boughtdur2_tabs
	do create_tableA4_boughtdur2_morttabs
	do create_tableA5_durables_real2var_tabs_robust
	do create_tableA6_durables_real2var_morttabs_robust
	do create_tableA7_boughtdur2_tabs_robust
	do create_tableA8_boughtdur2_morttabs_robust
	do create_tableA9_reg_tabs_nondurables_robust
	do create_tableA10_reg_morttabs_nondurables_robust
}

if `compile' == 1 {
cd ../Tables
forval i = 1/3 {
	/* replace ! with mv on MacOS or Unix systems */
	! pdflatex main_tables.tex
	! pdflatex appendix_extensive_margin_tables.tex
	! pdflatex appendix_robust_tables.tex
	! pdflatex appendix_full_specification_tables.tex
}
}
